# GS Demo FTP Sync Makefile

# 变量定义
BINARY_NAME=gs-demo-ftp-sync
BINARY_WINDOWS=$(BINARY_NAME).exe
BINARY_LINUX=$(BINARY_NAME)
BINARY_MACOS=$(BINARY_NAME)

# 默认目标
.PHONY: all
all: build

# 安装依赖
.PHONY: deps
deps:
	go mod tidy
	go mod download

# 构建Windows版本
.PHONY: build
build: deps
	go build -o $(BINARY_WINDOWS) .

# 构建优化版本（减小文件大小）
.PHONY: build-release
build-release: deps
	go build -ldflags="-s -w" -o $(BINARY_WINDOWS) .

# 构建Linux版本
.PHONY: build-linux
build-linux: deps
	GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o $(BINARY_LINUX) .

# 构建macOS版本
.PHONY: build-macos
build-macos: deps
	GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o $(BINARY_MACOS) .

# 构建所有平台版本
.PHONY: build-all
build-all: build build-linux build-macos

# 运行测试
.PHONY: test
test:
	go test -v ./...

# 运行代码检查
.PHONY: lint
lint:
	golangci-lint run

# 格式化代码
.PHONY: fmt
fmt:
	go fmt ./...

# 清理构建文件
.PHONY: clean
clean:
	rm -f $(BINARY_WINDOWS)
	rm -f $(BINARY_LINUX)
	rm -f $(BINARY_MACOS)

# 安装到系统
.PHONY: install
install: build
	go install .

# 运行程序（测试模式）
.PHONY: run-test
run-test: build
	./$(BINARY_WINDOWS) test

# 运行程序（监控模式）
.PHONY: run-watch
run-watch: build
	./$(BINARY_WINDOWS) watch

# 运行程序（同步模式）
.PHONY: run-sync
run-sync: build
	./$(BINARY_WINDOWS) sync

# 运行程序（完整同步）
.PHONY: run-full-sync
run-full-sync: build
	./$(BINARY_WINDOWS) full-sync

# 帮助信息
.PHONY: help
help:
	@echo "可用的命令:"
	@echo "  deps          - 安装依赖"
	@echo "  build         - 构建Windows版本"
	@echo "  build-release - 构建优化版本"
	@echo "  build-linux   - 构建Linux版本"
	@echo "  build-macos   - 构建macOS版本"
	@echo "  build-all     - 构建所有平台版本"
	@echo "  test          - 运行测试"
	@echo "  lint          - 运行代码检查"
	@echo "  fmt           - 格式化代码"
	@echo "  clean         - 清理构建文件"
	@echo "  install       - 安装到系统"
	@echo "  run-test      - 运行测试模式"
	@echo "  run-watch     - 运行监控模式"
	@echo "  run-sync      - 运行同步模式"
	@echo "  run-full-sync - 运行完整同步"
	@echo "  help          - 显示帮助信息"
